package com.ihr360.shared.sequence.expression.function;

import com.ihr360.expr.ExprException;
import com.ihr360.expr.context.IEvaluationContext;
import com.ihr360.expr.core.Expr;
import com.ihr360.expr.core.ExprFunction;
import com.ihr360.expr.core.IExprFunction;
import com.ihr360.expr.function.IFunctionProvider;

import java.util.HashMap;
import java.util.Map;

/**
 * @author davidwei
 */
public class SerialFunctionProvider implements IFunctionProvider {
    private static Map<String, IExprFunction> functions = new HashMap();
    static {
        functions.put("DATETIME",new DATETIME());
        functions.put("SERIALGEN", new SERIAL());
        functions.put("SERIALID", new SERIAL());
    }
    @Override
    public boolean hasFunction(ExprFunction function) {
        return functions.containsKey(function.getName().toUpperCase());
    }

    @Override
    public Expr evaluate(IEvaluationContext context, ExprFunction function)
            throws ExprException {
        IExprFunction f = functions.get(function.getName().toUpperCase());
        if (f != null)
            return f.evaluate(context, function.getArgs());
        return null;
    }
}